package com.cn.spjdbc;


import org.springframework.jdbc.support.KeyHolder;

public class TransformKeyTool {
	@SuppressWarnings("unchecked")
	public static <ID> ID getId(KeyHolder keyHolder,Class<ID> clazz){
		Number num = keyHolder.getKey();
		if(clazz.equals(Long.class)){
			return (ID) Long.valueOf(num.longValue());
		}else if(clazz.equals(Integer.class)){
			return (ID) Integer.valueOf(num.intValue());
		}else if(clazz.equals(Byte.class)){
			return (ID) Byte.valueOf(num.byteValue());
		}else if(clazz.equals(Double.class)){
			return (ID) Double.valueOf(num.doubleValue());
		}else if(clazz.equals(Float.class)){
			return (ID) Float.valueOf(num.floatValue());
		}else{
			throw new RuntimeException("unsupport primaty key type!");
		}
	} 
}
